import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@WebServlet("/stu")
public class StudentServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        List<Student> studentList=new ArrayList<Student>();
        Student student1=new Student();
        student1.setId(2);
        student1.setNum(123);
        student1.setName("dwh");

        Student student2=new Student();
        student2.setId(3);
        student2.setNum(124);
        student2.setName("lzm");

        Student student3=new Student();
        student3.setId(4);
        student3.setNum(125);
        student3.setName("zjh");

        Student student4=new Student();
        student4.setId(5);
        student4.setNum(126);
        student4.setName("yh");

        Student student5=new Student();
        student5.setId(6);
        student5.setNum(127);
        student5.setName("sry");

        studentList.add(student2);
        studentList.add(student3);
        studentList.add(student4);
        studentList.add(student5);
        studentList.add(student1);

        req.setAttribute("students",studentList);

        req.getRequestDispatcher("/student.jsp").forward(req,resp);
    }


}
